from wxpyview.ui.component.common.basewidget import *

class MenuItem(Widget):
    def _getParentParam(self, meta_widget):
        pass
    
    def _setParams(self, meta_widget):
        dom = meta_widget.getDOM()
        if not dom:
            raise IOException
        
        self.toggle = dom.getAttribute("toggle")
        
    def create(self, meta_widget):
        self._setParams(meta_widget)

        dom = meta_widget.getDOM()
        if not dom:
            raise IOException
    
        label = dom.getAttribute("label")
        accelerated = dom.getAttribute("accelerated")
        if accelerated != "":
            label = label + '\t' + accelerated
        
        #self.params["parent"].SetMenuBar(menuBar)
        parent = meta_widget.getParentMetaWidget().getWidget()
        #parent.Append(menu, self.label)
        parent_classname = parent.__class__.__name__
        
        menuitem = None
        
        if parent_classname == "Menu":
            if self.toggle == "check":
                menuitem = parent.AppendCheckItem(-1, label)
            elif self.toggle == "radio":
                menuitem = parent.AppendRadioItem(-1, label)
            else:
                menuitem = wx.MenuItem(parent, -1, label)
                parent.AppendItem(menuitem)
        else:
            raise Exception
        
        return menuitem